<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script type="text/javascript">
const A = new Set([1, 2, 3, 4, 5]);
const B = new Set([4, 5, 6, 7, 8]);

console.log("交集：", Array.from(new Set([...A].filter(x => B.has(x)))));
console.log("并集：", Array.from(new Set([...A,...B])));
console.log("差集（A - B）：", Array.from(new Set([...A].filter(x =>!B.has(x)))));
console.log("差集（B - A）：", Array.from(new Set([...B].filter(x =>!A.has(x)))));
    </script>
</body>

</html>